package com.laowang.project.system.controller;

import java.util.Date;
import java.util.List;

import com.laowang.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.MyCyhAdvice;
import com.laowang.project.system.service.MyCyhAdviceService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 意见与反馈Controller
 *
 * @author laowang
 * @date 2023-04-21
 */
@Api(tags = "意见与反馈接口")
@RestController
@RequestMapping("/advice")
public class MyCyhAdviceController extends BaseController {
    @Autowired
    private MyCyhAdviceService myCyhAdviceService;

    @ApiOperation(value = "小程序端 新增意见与反馈",notes = "")
    @PostMapping("/web/add")
    public AjaxResult add1(@RequestBody MyCyhAdvice myCyhAdvice) {
        Integer mid = SecurityUtils.getLoginUser().getWxUser().getMid();
        myCyhAdvice.setUserId(mid);
        myCyhAdvice.setCtime(new Date());
        return toAjax(myCyhAdviceService.insertMyCyhAdvice(myCyhAdvice));
    }


    /**
     * 查询意见与反馈列表
     */
    @ApiOperation(value = "查询意见与反馈列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:advice:list')")
    @GetMapping("/list")
        public TableDataInfo list(MyCyhAdvice myCyhAdvice) {
        startPage();
        List<MyCyhAdvice> list = myCyhAdviceService.selectMyCyhAdviceList(myCyhAdvice);
        return getDataTable(list);
    }

    /**
     * 导出意见与反馈列表
     */
    @ApiOperation(value = "导出意见与反馈列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:advice:export')")
    //@Log(title = "意见与反馈", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MyCyhAdvice myCyhAdvice) {
        List<MyCyhAdvice> list = myCyhAdviceService.selectMyCyhAdviceList(myCyhAdvice);
        ExcelUtil<MyCyhAdvice> util = new ExcelUtil<MyCyhAdvice>(MyCyhAdvice.class);
        return util.exportExcel(list, "advice");
    }

    /**
     * 获取意见与反馈详细信息
     */
    @ApiOperation(value = "获取意见与反馈详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:advice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(myCyhAdviceService.selectMyCyhAdviceById(id));
    }

    /**
     * 新增意见与反馈
     */
    @ApiOperation(value = "新增意见与反馈",notes = "")
    @PreAuthorize("@ss.hasPermi('my:advice:add')")
    //@Log(title = "意见与反馈", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyCyhAdvice myCyhAdvice) {
        return toAjax(myCyhAdviceService.insertMyCyhAdvice(myCyhAdvice));
    }

    /**
     * 修改意见与反馈
     */
    @ApiOperation(value = "修改意见与反馈",notes = "")
    @PreAuthorize("@ss.hasPermi('my:advice:edit')")
    //@Log(title = "意见与反馈", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyCyhAdvice myCyhAdvice) {
        return toAjax(myCyhAdviceService.updateMyCyhAdvice(myCyhAdvice));
    }

    /**
     * 删除意见与反馈
     */
    @ApiOperation(value = "删除意见与反馈",notes = "")
    @PreAuthorize("@ss.hasPermi('my:advice:remove')")
    //@Log(title = "意见与反馈", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(myCyhAdviceService.deleteMyCyhAdviceByIds(ids));
    }
}
